//
//  Helper.swift
//  weather
//
//  Created by 陈思斌 on 24/8/17.
//  Copyright © 2017年 陈思斌. All rights reserved.
//

import UIKit

let leftControllerAndRightControllerBgColor = UIColor(red: CGFloat(40.0/255.0), green: CGFloat(37.0/255.0), blue: CGFloat(40.0/255.0), alpha: 1.0)
let LeftControllerTypeChangeNotification = "LeftControllerTypeChangeNotification"
let AutoLocationNotification = "AutoLocationNotification"
let ChooseLocationCityNotification = "ChooseLocationCityNotification"
let CitiesKey = "CitiesKey"
let currentCityKey = "currentCityKey"
let deleteLocationCityNotification = "deleteLocationCityNotification"

//shareSDK
let shareKEY = "20951eae73900"
let shareSecret = "60b8a8c1ccde93a7741537f01f2b41a4"
// QQ
let qqID = "1106310065"
let qqKEY = "Ek5h0bnRjUyVmSvi"

//wechat
let wechatID = "wx25de5afc46710387"
let wechatKEY = "8290c59a646a9961325ee04a3e4ebcd9"

class Helper: NSObject {
    class func readCities()->[String]{
        let array = UserDefaults.standard.object(forKey: CitiesKey) as? NSArray
        
        if array == nil{
            return []
        }else{
            if array?.count == 0{
                return  []
            }else{
                var cities = [String]()
                for ele in array!{
                    cities.append(ele as! String)
                }
                return cities
            }
        }
    }
    class func insertCity(city:String){
        var allCities = readCities()
        let index = allCities.index(of: city)
        if allCities.contains(city){
            allCities.remove(at: index!)
        }
        allCities.insert(city, at: 0)
        let array = NSMutableArray()
        for ele in allCities{
            array.add(ele)
        }
        UserDefaults.standard.set(array, forKey: CitiesKey)
        UserDefaults.standard.synchronize()
    }
    class func deleteCity(city:String){
        var allCities = readCities()
        let index = allCities.index(of: city)
        if allCities.contains(city){
            allCities.remove(at: index!)
        }
        
        let array = NSMutableArray()
        for ele in allCities{
            array.add(ele)
        }
        UserDefaults.standard.set(array, forKey: CitiesKey)
        
    }
}
